package megrez.job.custom.domain;

import java.util.Date;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 * 
 * @author Lucky Yang
 * @since 2.6.9
 */
public interface LogRepository extends JpaRepository<Log, String>, JpaSpecificationExecutor<Log> {

    /**
     * 查询
     * 
     * @param config 
     * @return
     */
    List<Log> findByConfig(Config config);

    /**
     * 删除过期日志
     * 
     * @param createdDate
     */
    @Transactional
    @Modifying
    @Query("delete from Log where createdDate<?1 ")
    int deleteByCreatedDateLessThan(Date createdDate);

    @Transactional
    @Modifying
    @Query(value = "delete from job_log where config_id=?1", nativeQuery = true)
    int deleteByConfigId(String configId);

}
